﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PLC.Domain.Entity;

namespace PLC.Infrastructure.DbContext.Config;

public class ProductionDataConfig:IEntityTypeConfiguration<ProductionData>
{
    public void Configure(EntityTypeBuilder<ProductionData> builder)
    {
        builder.ToTable("tb_data_production");
        builder.HasKey(p => p.Id);
        builder.Property(p => p.Id).ValueGeneratedNever();
        builder.HasIndex(p => p.DeviceId);
        // 创建联合索引
        builder.HasIndex(p => new {p.TaskCode,p.LowerEndPlateCode,p.UpperEndPlateCode});
        builder.Property(p => p.LowerEndPlateCode).IsRequired().HasMaxLength(128).HasDefaultValue("");
        builder.Property(p => p.UpperEndPlateCode).HasMaxLength(128).IsRequired().HasDefaultValue("");
        builder.Property(p => p.TaskCode).HasMaxLength(128).IsRequired().HasDefaultValue("");
        builder.Property(p => p.Data).IsRequired().HasMaxLength(1024).HasDefaultValue("");
    }
}